package com.travel.controller;

import com.alipay.api.AlipayApiException;
import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbHomeOrder;
import com.travel.service.HotelService;
import com.travel.utils.ALiPayTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hotel")
public class FontHotelController {

    @Autowired
    HotelService hotelService;

    /**
     * 查找所有酒店
     * */
    @GetMapping("/getAll")
    public ResultMsg getAll(){
        return hotelService.getAll();
    }

    /**
     * 支付测试，没有测试
     * */
    @PostMapping("/topay")
    public ResultMsg topay(@RequestBody TbHomeOrder tbHomeOrder) throws AlipayApiException {
        ALiPayTools aliPayTools = new ALiPayTools();
        ResultMsg pay = aliPayTools.pay(tbHomeOrder);
        return pay;
    }


    /**
     * 按照城市名，酒店地址（模糊查询）查找所有酒店
     * */
    @GetMapping("/getAllByCnameHaddr")
    public ResultMsg getAllByCnameHaddr(String cityName, String hotelAddr){
        return hotelService.getAllByCnameHaddr(cityName,hotelAddr);
    }

    /**
     * 按照城市名查找所有酒店
     * */
    @GetMapping("/getAllByCityName")
    public ResultMsg getAllByCityName(String cityName){
        return hotelService.getAllByCityName(cityName);
    }

    /**
     * 按照id查找单个酒店
     * */
    @GetMapping("/getAllByHotelId")
    public ResultMsg getAllByHotelId(int hotelId){
        return hotelService.getAllByHotelId(hotelId);
    }

    /**
     * 随机推荐酒店信息
     * */
    @GetMapping("/recommendHotel")
    public ResultMsg recommendHotel(@RequestParam(defaultValue = "1") Integer nums){
        return hotelService.recommendHotel(nums);
    }

    /**
     * 根据价钱区间查询酒店信息
     * */
    @GetMapping("/getHotelBetween")
    public ResultMsg getHotelBetween(Integer min, Integer max){
        return hotelService.getHotelBetween(min,max);
    }


}
